package com.jsmtr.rms.controller;

import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jsmtr.rms.entity.*;
import com.jsmtr.rms.utils.StringTools;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.jsmtr.rms.entity.vo.ZZUserForm;
import com.jsmtr.rms.service.IRecommendService;
import com.jsmtr.rms.service.IDoZZService;
import com.jsmtr.rms.service.ISchoolService;
import com.jsmtr.rms.service.IUtilService;
import com.jsmtr.rms.utils.EnumTools;
import com.jsmtr.rms.utils.PhoneTools;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/Do/ZZPhysical")
public class DoZZPhysicalController {

    @Resource
    private IUtilService utilService;

    @Resource
    private IRecommendService recommendService;

    @Resource
    private ISchoolService schoolService;

    @Resource
    private IDoZZService doZZService;


    //[start] 查询毕业生信息

    //首页
    @RequestMapping("/")
    public String Index(HttpServletRequest request, Model model) {
        try {
            model.addAttribute("path", request.getContextPath());
            String pid = request.getParameter("pid").trim();
            String fid = request.getParameter("fid").trim();
            String deptcode = request.getParameter("deptcode").trim();

            model.addAttribute("pid", pid);
            model.addAttribute("fid", fid);
            model.addAttribute("deptcode", deptcode);

            StringBuilder str = new StringBuilder();
            List<HRSchoolUsers> schools = schoolService.getSchools();
            for (HRSchoolUsers school : schools) {
                str.append("<option value='" + school.getId() + "'>" + school.getUname() + "</option>");
            }
            model.addAttribute("school", str);

            List<BaseConfig> configs = utilService.getConfigs("dzmb");
            StringBuilder str1 = new StringBuilder();
            for (BaseConfig config : configs) {
                str1.append("<option value='" + config.getCont() + "'>" + config.getCont() + "</option>");
            }
            model.addAttribute("address", str1);

            List<String> dates = doZZService.getTjTimeList(pid, deptcode);
            StringBuilder str2 = new StringBuilder();
            for (String date : dates) {
                str2.append("<option value='" + date + "'>" + (date == null ? "" : date) + "</option>");
            }
            model.addAttribute("tjtime", str2);

            List<BaseConfig> _configs = utilService.getConfigs("dxmb");
            StringBuilder str3 = new StringBuilder();
            for (BaseConfig _config : _configs) {
                str3.append("<option value='" + _config.getCode() + "'>" + _config.getName() + "</option>");
            }
            model.addAttribute("dxmb", str3);

            //招聘岗位
            List<ProjectInfoJobs> projectJobs=utilService.getProjectJobs(pid);
            model.addAttribute("jobs",projectJobs);

            //结果状态
            List states=new ArrayList();
            List stateList=utilService.groupZZStateByFid(fid,"体检");
            if (stateList!=null&&stateList.size()>0){
                states.addAll(stateList);
            }else{
                states.add("未体检");
            }
            model.addAttribute("states",states);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "Do/ZZCampus/Physical/index";
    }

    @SuppressWarnings("unchecked")
    @RequestMapping("/getusers")
    public void getusers(HttpServletRequest request, HttpServletResponse response, HRZZUser user) {
        try {
            int perpage = Integer.parseInt(request.getParameter("perpage"));
            int page = Integer.parseInt(request.getParameter("page"));
            String flowid = request.getParameter("flowid").trim();
            user.setPath("/" + flowid + "/");
            Map<String, Object> _map = new HashMap<String, Object>();
            _map.put("agefrom", request.getParameter("agefrom")==null?"":request.getParameter("agefrom").trim());
            _map.put("ageto", request.getParameter("ageto")==null?"":request.getParameter("ageto").trim());
            _map.put("heightfrom", request.getParameter("heightfrom")==null?"":request.getParameter("heightfrom").trim());
            _map.put("heightto", request.getParameter("heightto")==null?"":request.getParameter("heightto").trim());
            _map.put("rcount",request.getParameter("graduationyear")==null?"":request.getParameter("graduationyear").trim());
            _map.put("ischangejob",request.getParameter("ischangejob"));
            String tjarrange=request.getParameter("tjarrange");
            if (StringTools.trimNotEmpty(tjarrange)){
                if (tjarrange.equalsIgnoreCase("未安排")){
                    _map.put("tjarrange"," is null ");
                }else if(tjarrange.equalsIgnoreCase("已安排")){
                    _map.put("tjarrange"," is not null ");
                }
            }
            Map<String, Object> map = recommendService.getUserMap(page, perpage, user,_map);
            StringBuilder result = new StringBuilder();
            double pageCount = (Double) map.get("pageCount");
            double allcount = (Double) map.get("count");

            if (pageCount != 0) {
               // Object object = map.get("list");
                List<HashMap> object = (List<HashMap>)map.get("list");
                int num = 0;
                for (HashMap<String,Object> _user :  object) {
                    result.append("<tr><td><input type=\"checkbox\" name='uid' value='" + _user.get("ID") + "' id='cb_" + _user.get("ID") + "' /></td>");
                    result.append("<td>" + (perpage * (page - 1) + num + 1) + "</td>");
                    result.append("<td class='link'><a target='_blank' href='"
                            + request.getContextPath() + "/UserResume/ViewDResume?id="
                            + _user.get("DRID") + "'>" + _user.get("NAME")
                            + "</a></td>");//简历ID和HRZZUser的ID相同
                    result.append("<td>" + _user.get("GENDER") + "</td>");
                    result.append("<td>" + _user.get("CODE") + "</td>");
                    result.append("<td>" + _user.get("MAJOR") + "<input type='hidden' name='user[" + num + "].id' value='" + _user.get("Id") + "' /></td>");
                    result.append("<td>" + (_user.get("JOB") == null ? "" : _user.get("JOB")) + "</td>");
                    result.append("<td>" + (_user.get("TJTIME") == null ? "" : _user.get("TJTIME")) + "</td>");
                    result.append("<td>" + (_user.get("TJADDRESS") == null ? "" : _user.get("TJADDRESS")) + "</td>");
                    result.append("<td>" + (_user.get("TJLXR") == null ? "" : (_user.get("TJLXR") + " " + _user.get("TJLXDH"))) + "</td>");
                    result.append("<td>" + _user.get("TJMSG") + "</td>");
                    result.append("<td>" + _user.get("TJSTATE") + "</td>");
                    if (_user.get("TJREMARK")==null||_user.get("TJREMARK").toString().equalsIgnoreCase("null")){
                        result.append("<td></td>");
                    }else{
                        result.append("<td>" + _user.get("TJREMARK") + "</td>");
                    }

                    //result.append("<td><div><select name='user[" + num + "].tjstate'>");
                   // result.append("<option value='未体检'>未体检</option><option value='已通过'>已通过</option><option value='未通过'>未通过</option>");
                    //result.append("</select><input type='hidden' value='" + _user.get("TJSTATE") + "' /></div></td>");
                   // result.append("<td><div><input type='text' name='user[" + num + "].tjremark' value='" + (_user.get("TJREMARK") == null ? "" : _user.get("TJREMARK")) + "' /></div></td>");
                    if (_user.get("OP5").equals("未公布")) {
                        result.append("<td class='true'><span>" + _user.get("OP5") + "</span></td>");
                    } else {
                        result.append("<td class='false'><span>" + _user.get("OP5") + "</span></td>");
                    }
                    /*if (_user.get("FQSTATE").equals("已放弃")
                            && _user.get("FQFID").equals(flowid)) {
                        result.append("<td class='yfq'><span>已放弃</span></td></tr>");
                    } else {
                        if (_user.get("TJSTATE").equals("不合格")||_user.get("TJSTATE").equals("不通过")||_user.get("TJSTATE").equals("未通过")) {
                            result.append("<td class='false'><span>已完成</span></td></tr>");
                        } else {
                            boolean bl = _user.get("FID").equals(flowid);
                            result.append("<td class='" + bl + "'><span>" + (bl == true ? "未完成" : "已完成") + "</span></td></tr>");
                        }
                    }*/

                    result.append("<td>");
                    if (_user.get("FQSTATE").equals("已放弃") && _user.get("FQFID").equals(flowid)) {
                        result.append("<span class='layui-badge layui-bg-gray' title='已放弃'>弃</span>");
                        //result.append("<td class='yfq'><span>已放弃</span></td></tr>");
                    } else {

                        if (_user.get("TJSTATE") == null) {
                            //result.append("<td class='true'><span>未完成</td></tr>");
                            result.append("<span class='layui-badge layui-bg-orange' title='未完成'>未</span>");
                        } else {
                            if (_user.get("TJSTATE").equals("不合格")||_user.get("TJSTATE").equals("未通过")||_user.get("TJSTATE").equals("不通过")||_user.get("TJSTATE").equals("未参加")) {
                                //result.append("<td class='false'><span>已完成</td></tr>");
                                result.append("<span class='layui-badge layui-bg-green' title='已完成'>完</span>");
                            } else {
                                if (_user.get("FID").equals(flowid)) {
                                    //result.append("<td class='true'><span>未完成</td></tr>");
                                    result.append("<span class='layui-badge layui-bg-orange' title='未完成'>未</span>");
                                } else {
                                    //result.append("<td class='false'><span>已完成</td></tr>");
                                    result.append("<span class='layui-badge layui-bg-green' title='已完成'>完</span>");
                                }
                            }
                        }

                    }
                    if (_user.get("NRID") != null) {
                        result.append("<span class='layui-badge layui-bg-blue' title='转岗(原岗位:"+_user.get("NJNAME")+")'>岗</span>");
                        //result.append("<td class='ytj'><span title='" + _user.get("NJNAME") + "'>已推荐</span></td></tr>");
                    }
                    result.append("</td>");
                    result.append("</tr>");

                    num++;
                }
            } else {
                result.append("<tr><td colspan='16'>未找到符合条件的数据</td></tr>");
            }
            result.append("<input type='hidden' id='pageCount' value='" + pageCount + "' />");
            result.append("<input type='hidden' id='allCount' value='" + allcount + "' />");
            utilService.printTextResult(result.toString(), response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printTextResult("<tr><td colspan='12'>读取数据失败</td></tr><input type='hidden' id='pageCount' value='0' /><input type='hidden' id='allCount' value='0' />", response);
        }

    }
    //[end]
    @ResponseBody
    @RequestMapping(value = "/getZzPhysicalListLayuiJson", method = RequestMethod.GET)
    public LayuiDataTableResultBean getZzPhysicalListLayuiJson(HttpServletRequest request, HttpServletResponse response, HRZZUser user) {
        try {
            int page = Integer.parseInt(request.getParameter("page"));
            int limit = Integer.parseInt(request.getParameter("limit"));
            String flowid = request.getParameter("flowid").trim();
            user.setPath("/" + flowid + "/");
            Map<String, Object> _map = new HashMap<String, Object>();
            _map.put("agefrom", request.getParameter("agefrom")==null?"":request.getParameter("agefrom").trim());
            _map.put("ageto", request.getParameter("ageto")==null?"":request.getParameter("ageto").trim());
            _map.put("heightfrom", request.getParameter("heightfrom")==null?"":request.getParameter("heightfrom").trim());
            _map.put("heightto", request.getParameter("heightto")==null?"":request.getParameter("heightto").trim());
            _map.put("rcount",request.getParameter("graduationyear")==null?"":request.getParameter("graduationyear").trim());
            _map.put("ischangejob",request.getParameter("ischangejob"));
            String tjarrange=request.getParameter("tjarrange");
            if (StringTools.trimNotEmpty(tjarrange)){
                if (tjarrange.equalsIgnoreCase("未安排")){
                    _map.put("tjarrange"," is null ");
                }else if(tjarrange.equalsIgnoreCase("已安排")){
                    _map.put("tjarrange"," is not null ");
                }
            }
            Map<String, Object> map = recommendService.getUserMap(page, limit, user,_map);

            double pageCount = (Double) map.get("pageCount");
            double allcount = (Double) map.get("count");

            JSONArray jsonArray = new JSONArray();
            int num = 1;
            if (pageCount != 0) {
                List<HashMap> object = (List<HashMap>)map.get("list");
                for (HashMap<String,Object> _user :  object) {
                    JSONObject jsonObject = new JSONObject();
                    jsonObject.put("id_cb", "cb_" + _user.get("ID"));
                    jsonObject.put("id", limit * (page - 1) + num);
                    jsonObject.put("NAME", _user.get("NAME"));
                    jsonObject.put("ContextPath", request.getContextPath() + "/UserResume/ViewDResume?id=" + _user.get("DRID"));
                    jsonObject.put("CARDNO", _user.get("CODE"));
                    jsonObject.put("SEXNAME", _user.get("GENDER"));
                    jsonObject.put("MAJOR", (_user.get("MAJOR") == null ? "" : _user.get("MAJOR")));
                    jsonObject.put("JOB", (_user.get("JOB") == null ? "" : _user.get("JOB")));
                    jsonObject.put("TJTIME", (_user.get("TJTIME") == null ? "" : _user.get("TJTIME")));
                    jsonObject.put("TJADDRESS", (_user.get("TJADDRESS") == null ? "" : _user.get("TJADDRESS")));
                    jsonObject.put("TJLXRs",  (_user.get("TJLXR") == null ? "" : (_user.get("TJLXR") + " " + _user.get("TJLXDH"))));
                    jsonObject.put("TJMSG", _user.get("TJMSG"));
                    jsonObject.put("TJSTATE", _user.get("TJSTATE"));
                    jsonObject.put("TJREMARK", (_user.get("TJREMARK") == null ? "" : _user.get("TJREMARK")));
                    jsonObject.put("MID", _user.get("MID"));
                    jsonObject.put("MCONTENT", (_user.get("MCONTENT") == null ? "" : _user.get("MCONTENT")));
                    jsonObject.put("STATEb",_user.get("OP5"));

                    jsonObject.put("FQSTATE", _user.get("FQSTATE"));
                    jsonObject.put("TJSTATE", _user.get("TJSTATE"));
                    jsonObject.put("FID", _user.get("FID"));
                    if (_user.get("FQSTATE").equals("已放弃") && _user.get("FQFID").equals(flowid)) {
                        jsonObject.put("STATEc", "弃");
                    } else {
                        if (_user.get("TJSTATE") == null) {
                            jsonObject.put("STATEc", "未");
                        } else {
                            if (_user.get("TJSTATE").equals("不合格")||_user.get("TJSTATE").equals("未通过")||_user.get("TJSTATE").equals("不通过")||_user.get("TJSTATE").equals("未参加")) {
                                jsonObject.put("STATEc", "完");
                            } else {
                                if (_user.get("FID").equals(flowid)) {
                                    jsonObject.put("STATEc", "未");
                                } else {
                                    jsonObject.put("STATEc", "完");
                                }
                            }
                        }
                    }

                    if (StringTools.trimNotEmpty(_user.get("NRID"))){
                        jsonObject.put("NJNAME", _user.get("NJNAME"));
                        jsonObject.put("STATEd", _user.get("岗"));
                        jsonObject.put("NRID", _user.get("NRID"));
                    }else
                        jsonObject.put("NRID", "");

                    jsonObject.put("arrange", _user.get("TJARRANGE"));

                    jsonArray.add(jsonObject);
                    num++;
                }
            }

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCode(0);
            result.setMsg("success");
            result.setCount((int) allcount);
            result.setData(jsonArray);

            return result;
        } catch (Exception e) {
            e.printStackTrace();

            LayuiDataTableResultBean result = new LayuiDataTableResultBean();
            result.setCount(-1);
            result.setMsg("err");
            return result;
        }
    }
    //[start] 体检安排

    @RequestMapping(value = "/PlanAction", method = RequestMethod.POST)
    public void PlanAction(HttpServletRequest request, HttpServletResponse response, HRZZUser user) {
        try {
            String[] uids = request.getParameterValues("uid");
            if (uids == null) {
                utilService.printJsonResult(false, "请选择参加体检的应聘者!", "no", response);
            } else {
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String tjzysx=request.getParameter("tjzysx");
                String pid=request.getParameter("pid");
                BaseUser cuser = utilService.getSessionUser(request);
                if (cuser.getUdept().equals(deptcode)) {
                    //流程是否结束
                    if (utilService.FlowIsDoing(fid)) {
                        List<HRZZUser> editlist = new ArrayList<HRZZUser>();
                        List<DoZysx> zysxList=new ArrayList<>();
                        for (String uid : uids) {
                            HRZZUser _user = recommendService.getViewUser(uid);
                            if (_user.getTjmsg().equals("未发通知")
                                    && _user.getDeptcode().equals(cuser.getUdept())
                                    && _user.getFqstate().equals("未放弃")
                                    && _user.getFid().equals(fid)) {
                                _user.setTjtime(user.getTjtime());
                                _user.setTjaddress(user.getTjaddress());
                                _user.setTjlxr(user.getTjlxr());
                                _user.setTjlxdh(user.getTjlxdh());
                                editlist.add(_user);
                            }
                            if(tjzysx!=null&&tjzysx.trim().length()>0){
                                DoZysx zysx=new DoZysx();
                                zysx.setId(UUID.randomUUID().toString());
                                zysx.setFid(fid);
                                zysx.setPid(pid);
                                zysx.setRemark(tjzysx);
                                zysx.setUserid(_user.getId());
                                zysx.setType("TJ");
                                zysx.setAddtime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                                zysx.setAdduser(cuser.getUcode());
                                zysxList.add(zysx);
                            }
                        }
                        if (editlist.size() > 0) {
                            utilService.editList(editlist);
                            if(zysxList.size()>0) {
                                utilService.addList(zysxList);
                            }
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "当前选中信息不支持此操作！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败!", "no", response);
        }
    }

    //[end]

    //[start] 发布体检通知

    @RequestMapping(value = "/MsgAction", method = RequestMethod.POST)
    public void MsgAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String pid = request.getParameter("pid").trim();//招聘方案ID
            String fid = request.getParameter("fid").trim();//招聘流程ID
            String deptcode = request.getParameter("deptcode").trim();//责任部门编码
            String[] uids = request.getParameterValues("uid");
            if (uids == null) {
                utilService.printJsonResult(false, "请选择参加体检的应聘者!", "no", response);
                return;
            }
            BaseUser cuser = utilService.getSessionUser(request);
            if (cuser.getUdept().equals(deptcode)) {
                //流程是否结束
                if (utilService.FlowIsDoing(fid)) {
                    List<HRZZUser> editlist = new ArrayList<HRZZUser>();
                    String tjtime = request.getParameter("tjtime").trim();
                    String dxnr = request.getParameter("dxnr").trim();

                    List<Map<String, String>> msgs = new ArrayList<Map<String, String>>();
                    for (String uid : uids) {
                        //List<HRZZUser> users = doZZService.getTjUsers(pid, deptcode, tjtime);
                        //for (HRZZUser user : users) {
                        HRZZUser user = recommendService.getViewUser(uid,pid);
                            if (user.getTjmsg().equals("未发通知") && user.getDeptcode().equals(cuser.getUdept()) && user.getFqstate().equals("未放弃") && user.getFid().equals(fid)) {
                                user.setTjmsg("已发通知");
                                editlist.add(user);

                                //-------------短信----------------
                                Map<String, String> _map = new HashMap<String, String>();
                                _map.put("tel", user.getTel());
                                _map.put("cont", dxnr.replace("{姓名}", user.getName()).replace("{时间}", user.getTjtime()).replace("{地点}", user.getTjaddress()));
                                msgs.add(_map);
                            }
                       // }
                    }
                    if (editlist.size() > 0) {
                        utilService.editList(editlist);
                        BaseMessageConfig messageConfig=utilService.getMessageConfig();
                        // 发送短信
                        if (PhoneTools.sendMsg(msgs,messageConfig.getUsername(),messageConfig.getPassword(),messageConfig.getHost())) {
                            utilService.printJsonResult(true, "操作成功！", "no", response);
                        } else {
                            utilService.printJsonResult(false, "短信发送失败！", "no", response);
                        }
                    } else {
                        utilService.printJsonResult(false, "无可执行此操作的信息！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }

    //[end]

    //[start] 获得短信模版内容

    @RequestMapping("/getMsg")
    public void getMsgCont(HttpServletRequest request, HttpServletResponse response) {
        try {
            String msg = utilService.getConfig(request.getParameter("code").trim());
            utilService.printTextResult(msg, response);
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printTextResult("", response);
        }
    }

    //[end]

    //[start] 导出体检人员信息

    @SuppressWarnings("unchecked")
    @RequestMapping(value = "/DownAction", method = RequestMethod.GET)
    public void DownAction(HttpServletRequest request, HttpServletResponse response, HRZZUser user) {
        response.setContentType("application/vnd.ms-excel");
        String codedFileName = null;
        OutputStream fOut = null;
        try {
            codedFileName = java.net.URLEncoder.encode("体检人员信息", "UTF-8");
            response.setHeader("content-disposition", "attachment;filename=" + codedFileName + ".xls");
            response.setCharacterEncoding("iso-8859-1");
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet();

            //[start] 表头样式
            HSSFCellStyle headerStyle = workbook.createCellStyle();
            //创建字体的对象
            HSSFFont font = workbook.createFont();
            //将字体加粗
            font.setBold(true);
            //垂直居中
            headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            //设置底边框;
            headerStyle.setBorderBottom(BorderStyle.THIN);
            //设置底边框颜色;
            headerStyle.setBottomBorderColor(IndexedColors.BLACK.index);
            //设置左边框;
            headerStyle.setBorderLeft(BorderStyle.THIN);
            //设置左边框颜色;
            headerStyle.setLeftBorderColor(IndexedColors.BLACK.index);
            //设置右边框;
            headerStyle.setBorderRight(BorderStyle.THIN);
            //设置右边框颜色;
            headerStyle.setRightBorderColor(IndexedColors.BLACK.index);
            //设置顶边框;
            headerStyle.setBorderTop(BorderStyle.THIN);
            //设置顶边框颜色;
            headerStyle.setTopBorderColor(IndexedColors.BLACK.index);
            //将新设置的字体属性放置到样式中
            headerStyle.setFont(font);

            //[end]

            //[start] 表格内容样式

            HSSFCellStyle bodyStyle = workbook.createCellStyle();
            //创建字体的对象
            HSSFFont _font = workbook.createFont();
            //垂直居中
            bodyStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            //设置底边框;
            bodyStyle.setBorderBottom(BorderStyle.THIN);
            //设置底边框颜色;
            bodyStyle.setBottomBorderColor(IndexedColors.BLACK.index);
            //设置左边框;
            bodyStyle.setBorderLeft(BorderStyle.THIN);
            //设置左边框颜色;
            bodyStyle.setLeftBorderColor(IndexedColors.BLACK.index);
            //设置右边框;
            bodyStyle.setBorderRight(BorderStyle.THIN);
            //设置右边框颜色;
            bodyStyle.setRightBorderColor(IndexedColors.BLACK.index);
            //设置顶边框;
            bodyStyle.setBorderTop(BorderStyle.THIN);
            //设置顶边框颜色;
            bodyStyle.setTopBorderColor(IndexedColors.BLACK.index);
            //将新设置的字体属性放置到样式中
            bodyStyle.setFont(_font);

            //[end]

            //[start] 笔试安排表头

            HSSFRow headrow = sheet.createRow(0);//创建一行
            headrow.setHeight((short) 400);

            HSSFCell headcel0 = headrow.createCell(0);
            headcel0.setCellValue(new HSSFRichTextString("编号"));
            headcel0.setCellStyle(headerStyle);

            HSSFCell headcel1 = headrow.createCell(1);
            headcel1.setCellValue(new HSSFRichTextString("姓名"));
            headcel1.setCellStyle(headerStyle);

            HSSFCell headcel2 = headrow.createCell(2);
            headcel2.setCellValue(new HSSFRichTextString("性别"));
            headcel2.setCellStyle(headerStyle);

            HSSFCell headcel3 = headrow.createCell(3);
            headcel3.setCellValue(new HSSFRichTextString("证件号码"));
            headcel3.setCellStyle(headerStyle);

            HSSFCell headcel4 = headrow.createCell(4);
            headcel4.setCellValue(new HSSFRichTextString("专业"));
            headcel4.setCellStyle(headerStyle);

            HSSFCell headcel5 = headrow.createCell(5);
            headcel5.setCellValue(new HSSFRichTextString("体检标准"));
            headcel5.setCellStyle(headerStyle);

            HSSFCell headcel6 = headrow.createCell(6);
            headcel6.setCellValue(new HSSFRichTextString("体检结果"));
            headcel6.setCellStyle(headerStyle);

            sheet.setColumnWidth(0, 0);
            sheet.setColumnWidth(1, 3000);
            sheet.setColumnWidth(2, 2000);
            sheet.setColumnWidth(3, 6000);
            sheet.setColumnWidth(4, 6000);
            sheet.setColumnWidth(5, 6000);
            sheet.setColumnWidth(6, 6000);


            //[end]

            Map<String, Object> map = doZZService.getTjResumes(user);
            Object object = map.get("list");

            int i = 1;
            for (Object[] _user : (List<Object[]>) object) {
                HSSFRow row = sheet.createRow(i);//创建一行
                row.setHeight((short) 400);
                for (int j = 0; j < 7; j++) {
                    HSSFCell cell = row.createCell(j);//创建一列
                    cell.setCellStyle(bodyStyle);
                    cell.setCellType(CellType.STRING);
                    //cell.setCellType(HSSFCell.CELL_TYPE_STRING);
                    if (j < 5) {
                        cell.setCellValue(new HSSFRichTextString(_user[j] == null ? "" : _user[j].toString()));
                    }else {
                        cell.setCellValue(new HSSFRichTextString(""));
                    }
                }
                i++;
            }

            fOut = response.getOutputStream();
            workbook.write(fOut);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                fOut.flush();
                fOut.close();
            } catch (IOException e) {
            }
        }
    }

    //[end]

    //[start] 提交体检结果

    @RequestMapping(value = "/RAction", method = RequestMethod.POST)
    public void RAction(HttpServletRequest request, HttpServletResponse response, ZZUserForm users) {
        try {
            String fid = request.getParameter("fid").trim();//招聘流程ID
            String deptcode = request.getParameter("deptcode").trim();//责任部门编码
            String[] uids = request.getParameterValues("uid");
            String tjstate=request.getParameter("tjstate");
            String tjremark=request.getParameter("tjremark");
            if (uids == null) {
                utilService.printJsonResult(false, "请选择参加体检的应聘者!", "no", response);
                return;
            }
            BaseUser cuser = utilService.getSessionUser(request);
            if (cuser.getUdept().equals(deptcode)) {
                //流程是否结束
                if (utilService.FlowIsDoing(fid)) {
                    Date time = new Date();
                    List<HRZZUser> editlist = new ArrayList<HRZZUser>();
                   // for (HRZZUser user : users.getUser()) {
                    //    HRZZUser usr = recommendService.getViewUser(user.getId());
                    for (String uid : uids) {
                        HRZZUser usr = recommendService.getViewUser(uid);
                        if (usr.getDeptcode().equals(cuser.getUdept())
                                && usr.getFqstate().equals("未放弃")
                                && usr.getFid().equals(fid)
                               // && usr.getTjmsg().equals("已发通知")
                                ) {
                           // usr.setTjstate(user.getTjstate());
                          //  usr.setTjremark(user.getTjremark());
                            usr.setTjstate(tjstate);
                            usr.setTjremark(tjremark);
                            usr.setTjdate(time);
                            usr.setTjuid(cuser.getId());
                            usr.setTjuname(cuser.getUname());

                            editlist.add(usr);
                        }
                    }
                    if (editlist.size() > 0) {
                        utilService.editList(editlist);
                        utilService.printJsonResult(true, "操作成功！", "no", response);
                    } else {
                        utilService.printJsonResult(false, "当前信息不支持此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "当前流程不支持此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }
    //[end]

    //[start] 流程扭转到下一步

    @SuppressWarnings({"rawtypes", "unchecked"})
    @RequestMapping(value = "/NextAction", method = RequestMethod.POST)
    public void NextAction(HttpServletRequest request, HttpServletResponse response) {
        try {
            String[] ids = request.getParameterValues("id");//人员信息ID
            if (ids != null) {
                String pid = request.getParameter("pid").trim();//招聘方案ID
                String fid = request.getParameter("fid").trim();//招聘流程ID
                String deptcode = request.getParameter("deptcode").trim();//责任部门编码
                BaseUser usr = utilService.getSessionUser(request);
                if (usr.getUdept().equals(deptcode)) {
                    List editlist = new ArrayList();
                    List<HRZZUser> users = doZZService.getUsers(pid, deptcode, ids);
                    ProjectInfoFlow nFlow = doZZService.getNextFlow(pid, deptcode, fid);
                    for (HRZZUser user : users) {
                        if (user.getFid().equals(fid)&& user.getFqstate().equals("未放弃")) {
                            if(user.getTjstate().equals("通过")||user.getTjstate().equals("已通过")||user.getTjstate().equals("合格")){
                                user.setFid(nFlow.getId());
                                user.setPath(user.getPath() + nFlow.getId() + "/");
                                editlist.add(user);
                            }
                        }
                    }
                    if (editlist.size() > 0) {
                        nFlow.setState(EnumTools.PlanFlowState.进行中.ordinal());
                        editlist.add(nFlow);

                        utilService.editList(editlist);
                        utilService.printJsonResult(true, "操作成功！", "no", response);
                    } else {
                        utilService.printJsonResult(false, "当前选中的信息不能执行此操作！", "no", response);
                    }
                } else {
                    utilService.printJsonResult(false, "您无权执行此操作！", "no", response);
                }
            } else {
                utilService.printJsonResult(false, "请选择人员信息！", "no", response);
            }
        } catch (Exception e) {
            e.printStackTrace();
            utilService.printJsonResult(false, "操作失败！", "no", response);
        }
    }

    //[end]
}
